package mr;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class Demo2Split128 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("E:\\IDEJAVA\\mapreduce\\data\\students.txt"));

        int index=0;
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\IDEJAVA\\mapreduce\\split01\\split--"+index));
        ArrayList<String> list = new ArrayList<String>();
        String line;
        int flag=0;
        int row=0;
        while ((line=br.readLine())!=null){
            list.add(line);
            flag++;
            if(flag==140){//一个文件读写完成,生成新的文件
                row=0+128*index;
                for (int i = row; i <=row+127; i++) {
                    bw.write(list.get(i));
                    bw.newLine();
                }
                bw.flush();
                bw.close();

                index++;
                flag=12;
                bw = new BufferedWriter(new FileWriter("E:\\IDEJAVA\\mapreduce\\split01\\split--"+index));
            }
        }
         //文件读取剩余在128*1.1范围内
        for (int i = list.size()-flag; i <list.size(); i++) {
            bw.write(list.get(i));
            bw.newLine();
        }
        bw.flush();
        bw.close();

    }
}
